/*
 * @(#) AttendanceServiceImpl.java 2011-9-17
 *
 * Copyright (c) 2011, Strong Technology. All Rights Reserved.
 * Strong Technology. CONFIDENTIAL
 */
package cn.strong.gweva.attendance.business.service.impl;

import java.util.Date;

import cn.strong.gweva.attendance.business.entity.AttendanceRecordEntity;
import cn.strong.gweva.attendance.business.entity.AttendanceRecordSearchEntity;
import cn.strong.gweva.attendance.business.service.AttendanceService;
import cn.strong.gweva.common.business.entity.LoginEntity;
import cn.strong.gweva.common.business.entity.PagerEntity;
import cn.strong.gweva.common.business.service.impl.AbstractServiceImpl;
import cn.strong.gweva.common.util.Constants;
import cn.strong.gweva.common.util.Constants4Method;

/**
 * 日常考勤业务处理。
 * 
 * @author lilanfei
 * @version 1.0
 * @since 2011-9-17
 */
public class AttendanceServiceImpl extends AbstractServiceImpl implements AttendanceService
{
	/**
	 * 检索考勤记录分页信息
	 * 
	 * @param pagerEntity
	 * @param attendanceRecord4Search 检索用考勤记录信息
	 * @return 用户分页信息
	 * @throws Exception
	 */
	public PagerEntity searchAttendanceRecordPage(PagerEntity pagerEntity, AttendanceRecordSearchEntity searchEnity) throws Exception
	{
		return this.getCommonDao().searchPager(pagerEntity,
				Constants4Method.ATTENDANCE_SEARCH_ATTENDANCE_RECORD_LIST, searchEnity);
	}
	
	/**
	 * 通过考勤记录编号，检索考勤记录信息。
	 * 
	 * @param attendanceId 考勤记录编号
	 * @return
	 * @throws Exception
	 */
	public AttendanceRecordEntity searchAttendanceRecordById(Integer attendanceId) throws Exception
	{
		return (AttendanceRecordEntity)this.getCommonDao().searchObj(Constants4Method.ATTENDANCE_SEARCH_ATTENDANCE_RECORD_BY_ID, attendanceId);
	}

	/**
	 * 校验考勤记录的唯一性
	 * 
	 * @param attendanceRecord 考勤记录
	 * @return 记录件数
	 * @throws Exception
	 */
	public int checkUniqueness(AttendanceRecordEntity attendanceRecord) throws Exception
	{
		return this.getCommonDao().searchCount(Constants4Method.ATTENDANCE_CHECK_UNIQUENESS, attendanceRecord);
	}

	/**
	 * 新增考勤记录
	 * 
	 * @param attendanceRecord 考勤记录
	 * @param loginUser 登录用户
	 * @return 考勤记录
	 * @throws Exception
	 */
	public AttendanceRecordEntity insert(AttendanceRecordEntity attendanceRecord, LoginEntity loginUser) throws Exception
	{
		attendanceRecord.setUpdateUserId(loginUser.getUserId());
		attendanceRecord.setUpdateTime(new Date());
		attendanceRecord.setDelFlag(Constants.DEL_FLAG_NO);
		
		this.getCommonDao().insert(Constants4Method.ATTENDANCE_INSERT_ATTENDANCE_RECORD, attendanceRecord);
		
		return attendanceRecord;
	}
	
	/**
	 * 通过考勤记录编号，逻辑删除考勤记录。
	 * 
	 * @param attendanceRecord 考勤记录
	 * @param loginUser 登录用户
	 * @return
	 * @throws Exception
	 */
	public int logicDeleteById(AttendanceRecordEntity attendanceRecord, LoginEntity loginUser) throws Exception
	{
		attendanceRecord.setDelFlag(Constants.DEL_FLAG_YES);
		attendanceRecord.setUpdateTime(new Date());
		attendanceRecord.setUpdateUserId(loginUser.getUserId());
		return this.getCommonDao().update(Constants4Method.ATTENDANCE_LOGIC_DELETE_BY_ID, attendanceRecord);
	}
	
	/**
	 * 通过考勤记录编号，删除考勤记录。
	 * 
	 * @param attendanceId 考勤记录编号
	 * @return
	 * @throws Exception
	 */
	public int deleteById(Integer attendanceId) throws Exception
	{
		return this.getCommonDao().delete(Constants4Method.ATTENDANCE_DELETE_BY_ID, attendanceId);
	}
	
	/**
	 * 更新考勤记录信息。
	 * 
	 * @param attendanceRecord 更新的考勤记录信息
	 * @param loginUser 登录的用户
	 * @return
	 * @throws Exception
	 */
	public int update(AttendanceRecordEntity attendanceRecord, LoginEntity loginUser) throws Exception
	{
		attendanceRecord.setUpdateTime(new Date());
		attendanceRecord.setUpdateUserId(loginUser.getUserId());
		
		return this.getCommonDao().update(Constants4Method.ATTENDANCE_UPDATE_ATTENDANCE_RECORD, attendanceRecord);
	}
}
